package com.zjw.xm.xmorder.mapper;

import com.zjw.xm.entity.CrBook;
import com.zjw.xm.entity.CrCategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zjw1
 * @since 2022-08-03
 */
@Mapper
public interface CrCategoryMapper extends BaseMapper<CrCategory> {


    // 详情页面左边的分类查询
    @Select(" select * from cr_category where pid is null ")
    @Results(id="rm1",value={
            @Result(property = "id", column = "id"),
            @Result(property = "seconds", column = "id",
                    many = @Many(select = "queryCategoryAll"))
    })
    List<CrCategory> queryCategory();

    @Select("select * from cr_category where pid =#{pid}")
    @ResultMap("rm1")
    List<CrCategory> queryCategoryAll(int pid);






    //首页数据查询
    @Select(" select * from cr_category where pid is null ")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "seconds", column = "id",
                    many = @Many(select = "selectCategoryAndBook"))
    })
    List<CrCategory> selectCategory();

    @Select("select * from cr_category where pid =#{pid}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "books",column = "id",
            many = @Many(select = "selectBook"))
    })
    List<CrCategory> selectCategoryAndBook(int pid);

    @Select("select * from cr_book where category2=#{category2} limit 1, 5 ")
    List<CrBook> selectBook(int category2);


}
